<template>
	<div class="page-wrap">
		<page-title></page-title>
		<div class="back">
			<el-button @click="goback" type="primary" size="small">返回</el-button>
		</div>
		<div class="page-content">
			<div class="page-row">
				<div class="box-right">
					<div class="table-box">
						<el-tabs v-model="activeTab" class="flex-tabs">
							<el-tab-pane name="1" label="文件选择" lazy>
								<fileselect ref="file" v-on:changeActiveTab="changeActive($event)"></fileselect>
							</el-tab-pane>
							<el-tab-pane name="2" :disabled="this.showactiveTab < 2" label="事故设置" lazy>
								<accident v-on:changeActiveTab="changeActive($event)"></accident>
							</el-tab-pane>
							<el-tab-pane name="3" :disabled="this.showactiveTab < 3" label="食入设置" lazy>
								<ingestionSet v-on:changeActiveTab="changeActive($event)"></ingestionSet>
							</el-tab-pane>
						</el-tabs>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import fileselect from "./fileselect.vue"
import ingestionSet from "./ingestionSet.vue"
import accident from "./accident.vue"
import { mapState } from "vuex"
export default {
	components: {
		fileselect,
		ingestionSet,
		accident,
	},
	data() {
		return {
			activeTab: "1",
		}
	},
	computed: {
		...mapState({
			showactiveTab: (state) => state.token.ingestion_show_Tab,
			ingestion_Data: (state) => state.token.ingestion_Data,
		}),
	},

	mounted() {
		this.getBasicData()
		this.getearlyData()
		this.getingestionData()
		// console.log(this.activeTab)
		// console.log(this.showactiveTab)
		this.$emit("changeActiveTab", this.activeTab)
		this.$store.dispatch("change_ingestion_showTab", this.activeTab)
		this.router()
	},
	methods: {
		//配置面包屑
		router() {
			let temproute = []
			let advert = {
				resrName: "食入模块",
			}
			temproute.push(advert)
			this.$store.commit("updateRoute", temproute)
		},
		goback() {
			this.$router.go(-1)
			this.$emit("result")
		},
		changeActive(value) {
			// console.log(value)
			this.activeTab = value
		},
		getBasicData() {
			//基本
			// let params = {
			// 	batchid: this.$route.query.id,
			// 	batchinfo: "BASE",
			// }
			// console.log(params)
			// this.$appApi
			// 	.BATCH_DETAIL(params)
			// 	.then((res) => {
			// 		let tempdata = JSON.parse(res.data.substring(8))
			// 		this.$store.dispatch("upData_basic_Data", tempdata)
			// 		console.log(this.basic_Data)
			// 	})
			// 	.catch((err) => {
			// 		console.log(err)
			// 	})
		},
		getearlyData() {
			//早期
			// let params = {
			// 	batchid: this.$route.query.id,
			// 	batchinfo: "ZAOQI",
			// }
			// console.log(params)
			// this.$appApi
			// 	.BATCH_DETAIL(params)
			// 	.then((res) => {
			// 		var str = JSON.parse(res.data.substring(8))
			// 		console.log(str)
			// 		let tempdata = str
			// 		this.$store.dispatch("upData_early_Data", tempdata)
			// 	})
			// 	.catch((err) => {
			// 		console.log(err)
			// 	})
		},
		getlongtermData() {
			//获取长期模块
			// let params = {
			// 	batchid: this.$route.query.id,
			// 	batchinfo: "CHANGQI",
			// }
			// console.log(params)
			// this.$appApi
			// 	.BATCH_DETAIL(params)
			// 	.then((res) => {
			// 		var str = JSON.parse(res.data.substring(8))
			// 		console.log(str)
			// 		let tempdata = str
			// 		this.$store.dispatch("upData_longterm_Data", tempdata)
			// 		console.log(this.longterm_Data)
			// 	})
			// 	.catch((err) => {
			// 		console.log(err)
			// 	})
		},
		getingestionData() {
			//获取食入模块
			let params = {
				batchid: this.$route.query.id,
				batchinfo: "SHIRU",
			}
			// console.log(params)
			this.$appApi
				.BATCH_DETAIL(params)
				.then((res) => {
					var str = res.data.substring(0, 1)
					if (str == "E") {
						let message = res.data.substring(6)
						this.$notify.error({
							title: "请求数据失败！",
							message: message,
							type: "success",
						})
					} else if (str == "S") {
						let tempdata = JSON.parse(res.data.substring(8))
						this.$store.dispatch(
						"change_ingestion_showTab",
						tempdata.SETPAGEINDEX
					   )
						this.$store.dispatch("upData_ingestion_Data", tempdata)
						this.$refs.file.setData()
					}
				})
				.catch((err) => {
					console.log(err)
				})
		},
	},
}
</script>